package com.eee.xiang.market.controller;


import com.eee.xiang.market.beans.OperateResponse;
import com.eee.xiang.market.beans.TCargo;
import com.eee.xiang.market.common.TableData;
import com.eee.xiang.market.service.ICargoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

@RestController
@RequestMapping("/cargoManager")
public class CargoManagerController {

    @Autowired
    private ICargoService cargoService;

    @RequestMapping("/uploadImg")
    OperateResponse uploadImg(MultipartFile imgFile, HttpServletRequest request) throws FileNotFoundException {
        return cargoService.uploadImg(imgFile);
    }

    @RequestMapping("/saveCargo")
    OperateResponse saveCargo(TCargo cargoForm) throws FileNotFoundException {
        return cargoService.saveCargo(cargoForm);
    }

    @RequestMapping("/getAllCargo")
    @ResponseBody
    TableData getAllCargoList(@RequestParam(value = "page") int page,
                              @RequestParam(value = "limit") int limit){
        return cargoService.getAllCargoList(page, limit);
    }

    @RequestMapping("/getDetailCargo")
    OperateResponse getDetailCargo(){
        return cargoService.getDetailCargo();
    }

    @RequestMapping("/delCargo")
    OperateResponse delCargo(String cargoId){
        return cargoService.delCargo(cargoId);
    }


}
